# @HEADER
# ************************************************************************
#
#            TriBITS: Tribal Build, Integrate, and Test System
#                    Copyright 2013 Sandia Corporation
#
#
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the Corporation nor the names of the
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ************************************************************************
# @HEADER

##############################################################################
#
# CMake variable for use by ${PROJECT_NAME} clients. 
#
# ${DISCOURAGE_EDITING}
#
##############################################################################

#
# Ensure CMAKE_CURRENT_LIST_DIR is usable.
#
${DEFINE_CMAKE_CURRENT_LIST_DIR_CODE_SNIPPET}

## ---------------------------------------------------------------------------
## Compilers used by ${PROJECT_NAME} build
## ---------------------------------------------------------------------------

SET(${PROJECT_NAME}_CXX_COMPILER "${CMAKE_CXX_COMPILER}")

SET(${PROJECT_NAME}_C_COMPILER "${CMAKE_C_COMPILER}")

SET(${PROJECT_NAME}_Fortran_COMPILER "${CMAKE_Fortran_COMPILER}")

## ---------------------------------------------------------------------------
## Compiler flags used by ${PROJECT_NAME} build
## ---------------------------------------------------------------------------

SET(${PROJECT_NAME}_CXX_COMPILER_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}")

SET(${PROJECT_NAME}_C_COMPILER_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}")

SET(${PROJECT_NAME}_Fortran_COMPILER_FLAGS "${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}}")

## Extra link flags (e.g., specification of fortran libraries)
SET(${PROJECT_NAME}_EXTRA_LD_FLAGS "${${PROJECT_NAME}_EXTRA_LINK_FLAGS}")

## This is the command-line entry used for setting rpaths. In a build
## with static libraries it will be empty. 
SET(${PROJECT_NAME}_SHARED_LIB_RPATH_COMMAND "${SHARED_LIB_RPATH_COMMAND}")
SET(${PROJECT_NAME}_BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS}")

SET(${PROJECT_NAME}_LINKER ${CMAKE_LINKER})
SET(${PROJECT_NAME}_AR ${CMAKE_AR})


## ---------------------------------------------------------------------------
## Set library specifications and paths 
## ---------------------------------------------------------------------------

## The project version number
SET(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION}")

## The project include file directories.
#SET(${PROJECT_NAME}_INCLUDE_DIRS "${${PROJECT_NAME}_CONFIG_INCLUDE_DIRS}")

## The project library directories.
#SET(${PROJECT_NAME}_LIBRARY_DIRS "${${PROJECT_NAME}_CONFIG_LIBRARY_DIRS}")

## The project libraries.
#SET(${PROJECT_NAME}_LIBRARIES "${${PROJECT_NAME}_CONFIG_LIBRARIES}")

## The project tpl include paths
#SET(${PROJECT_NAME}_TPL_INCLUDE_DIRS "${${PROJECT_NAME}_CONFIG_TPL_INCLUDE_DIRS}")

## The project tpl library paths
#SET(${PROJECT_NAME}_TPL_LIBRARY_DIRS "${${PROJECT_NAME}_CONFIG_TPL_LIBRARY_DIRS}")

## The project tpl libraries
#SET(${PROJECT_NAME}_TPL_LIBRARIES "${${PROJECT_NAME}_CONFIG_TPL_LIBRARIES}")

# For best practices in handling of components, see
# <http://www.cmake.org/cmake/help/v3.2/manual/cmake-developer.7.html#find-modules>.
#
# If components were requested, include only those. If not, include all of
# Trilinos.
IF (${PROJECT_NAME}_FIND_COMPONENTS)
  SET(COMPONENTS_LIST ${PDOLLAR}{${PROJECT_NAME}_FIND_COMPONENTS})
ELSE()
  SET(COMPONENTS_LIST ${FULL_PACKAGE_SET})
ENDIF()

# Initialize ${PROJECT_NAME}_FOUND with true, and set it to FALSE if any of
# the required components wasn't found.
SET(${PROJECT_NAME}_FOUND TRUE)
FOREACH(comp ${PDOLLAR}{COMPONENTS_LIST})
   SET(
     INCLUDE_FILE
     ${PDOLLAR}{CMAKE_CURRENT_LIST_DIR}/../${PDOLLAR}{comp}/${PDOLLAR}{comp}Config.cmake
     )
   IF (EXISTS ${PDOLLAR}{INCLUDE_FILE})
       # Set ${PROJECT_NAME}_<component>_FOUND.
       SET(${PROJECT_NAME}_${PDOLLAR}{comp}_FOUND TRUE)
       # Include the package file.
       INCLUDE(${PDOLLAR}{INCLUDE_FILE})
       # Add variables to lists.
       LIST(APPEND ${PROJECT_NAME}_INCLUDE_DIRS ${PDOLLAR}{${PDOLLAR}{comp}_INCLUDE_DIRS})
       LIST(APPEND ${PROJECT_NAME}_LIBRARY_DIRS ${PDOLLAR}{${PDOLLAR}{comp}_LIBRARY_DIRS})
       LIST(APPEND ${PROJECT_NAME}_LIBRARIES ${PDOLLAR}{${PDOLLAR}{comp}_LIBRARIES})
       LIST(APPEND ${PROJECT_NAME}_TPL_INCLUDE_DIRS ${PDOLLAR}{${PDOLLAR}{comp}_TPL_INCLUDE_DIRS})
       LIST(APPEND ${PROJECT_NAME}_TPL_LIBRARY_DIRS ${PDOLLAR}{${PDOLLAR}{comp}_TPL_LIBRARY_DIRS})
       LIST(APPEND ${PROJECT_NAME}_TPL_LIBRARIES ${PDOLLAR}{${PDOLLAR}{comp}_TPL_LIBRARIES})
   ELSE()
       # Component not found.
       MESSAGE(WARNING "Component \"${PDOLLAR}{comp}\" NOT found.")
       # Set ${PROJECT_NAME}_<component>_FOUND to FALSE.
       SET(${PROJECT_NAME}_${PDOLLAR}{comp}_FOUND FALSE)
       # Set ${PROJECT_NAME}_FOUND to FALSE if component is not optional.
       IF(${PROJECT_NAME}_FIND_REQUIRED_${PDOLLAR}{comp})
           SET(${PROJECT_NAME}_FOUND FALSE)
       ENDIF()
   ENDIF()
ENDFOREACH()

# Resolve absolute paths and remove duplicate paths
# for LIBRARY_DIRS and INCLUDE_DIRS
# This reduces stress on regular expressions later
SET(short_dirs)
FOREACH(dir ${PDOLLAR}{${PROJECT_NAME}_INCLUDE_DIRS})
  GET_FILENAME_COMPONENT(dir_abs ${PDOLLAR}{dir} ABSOLUTE)
  LIST(APPEND short_dirs ${PDOLLAR}{dir_abs})
ENDFOREACH()
LIST(REMOVE_DUPLICATES short_dirs)
SET(${PROJECT_NAME}_INCLUDE_DIRS ${PDOLLAR}{short_dirs})

SET(short_dirs)
FOREACH(dir ${PDOLLAR}{${PROJECT_NAME}_LIBRARY_DIRS})
  GET_FILENAME_COMPONENT(dir_abs ${PDOLLAR}{dir} ABSOLUTE)
  LIST(APPEND short_dirs ${PDOLLAR}{dir_abs})
ENDFOREACH()
LIST(REMOVE_DUPLICATES short_dirs)
SET(${PROJECT_NAME}_LIBRARY_DIRS ${PDOLLAR}{short_dirs})

## ---------------------------------------------------------------------------
## MPI specific variables
##   These variables are provided to make it easier to get the mpi libraries
##   and includes on systems that do not use the mpi wrappers for compiling
## ---------------------------------------------------------------------------

SET(${PROJECT_NAME}_MPI_LIBRARIES "${TPL_MPI_LIBRARIES}")
SET(${PROJECT_NAME}_MPI_LIBRARY_DIRS "${TPL_MPI_LIBRARY_DIRS}")
SET(${PROJECT_NAME}_MPI_INCLUDE_DIRS "${TPL_MPI_INCLUDE_DIRS}")
SET(${PROJECT_NAME}_MPI_EXEC "${MPI_EXEC}")
SET(${PROJECT_NAME}_MPI_EXEC_MAX_NUMPROCS "${MPI_EXEC_MAX_NUMPROCS}")
SET(${PROJECT_NAME}_MPI_EXEC_NUMPROCS_FLAG "${MPI_EXEC_NUMPROCS_FLAG}")

## ---------------------------------------------------------------------------
## Compiler vendor identifications
## ---------------------------------------------------------------------------
SET(${PROJECT_NAME}_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
SET(${PROJECT_NAME}_CXX_COMPILER_ID "${CMAKE_CXX_COMPILER_ID}")
SET(${PROJECT_NAME}_C_COMPILER_ID "${CMAKE_C_COMPILER_ID}")
SET(${PROJECT_NAME}_Fortran_COMPILER_ID "${CMAKE_Fortran_COMPILER_ID}")
SET(${PROJECT_NAME}_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")

## ---------------------------------------------------------------------------
## Set useful general variables 
## ---------------------------------------------------------------------------

## The packages enabled for this project
SET(${PROJECT_NAME}_PACKAGE_LIST "${FULL_PACKAGE_SET}")

## The TPLs enabled for this project
SET(${PROJECT_NAME}_TPL_LIST "${FULL_TPL_SET}")

${PROJECT_CONFIG_CODE}
